package com.owen.server.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.owen.dao.DictionaryDao;
import com.owen.dao.InterviewDao;
import com.owen.pojo.Dictionary;
import com.owen.pojo.Interview;
import com.owen.server.DictionaryServer;
import com.owen.server.InterviewServer;
import com.owen.utils.ftl.GenerateDocxUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Service
public class DictionaryServerImpl implements DictionaryServer {

    @Autowired
    private DictionaryDao dictionaryDao;

    @Override
    public PageInfo<Dictionary> findAll(Integer pageNum, Integer pageSize) {
        pageNum = Optional.ofNullable(pageNum).map(p -> p < 1 ? 1 : p).orElse(1);
        pageSize = Optional.ofNullable(pageSize).map(p -> p < 1 ? 10 : p).orElse(10);
        PageHelper.startPage(pageNum, pageSize);
        List<Dictionary> dictionaryAll = dictionaryDao.findAll();
        PageInfo<Dictionary> pageInfo = new PageInfo<Dictionary>(dictionaryAll);
        return pageInfo;
    }

    @Override
    public PageInfo<Dictionary> findByDictionary(Dictionary dictionary, Integer pageNum, Integer pageSize) {
        pageNum = Optional.ofNullable(pageNum).map(p -> p < 1 ? 1 : p).orElse(1);
        pageSize = Optional.ofNullable(pageSize).map(p -> p < 1 ? 10 : p).orElse(10);
        PageHelper.startPage(pageNum, pageSize);
        List<Dictionary> dictionaryAll = dictionaryDao.findByDictionary(dictionary);
        PageInfo<Dictionary> pageInfo = new PageInfo<Dictionary>(dictionaryAll);
        return pageInfo;
    }

    @Override
    public List<Dictionary> findByDictionary(Dictionary dictionary) {
        List<Dictionary> dictionaryAll = dictionaryDao.findByDictionary(dictionary);
        return dictionaryAll;
    }

    @Override
    public Dictionary findById(Integer id) {
        return dictionaryDao.findById(id);
    }

    @Override
    public Integer deleteById(Integer id) {
        return dictionaryDao.deleteById(id);
    }

    @Override
    public Integer deleteBatch(Integer[] ids) {
        return dictionaryDao.deleteBatch(ids);
    }

    @Override
    public Integer save(Dictionary dictionary) {
        return dictionaryDao.save(dictionary);
    }

    @Override
    public Integer update(Dictionary dictionary) {
        return dictionaryDao.update(dictionary);
    }

}
